/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SMeterInputConverter.java
 * Created：		2016年8月30日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.device.inspect.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.AAttachmentConverter;
import com.thor.palmmall.rest.device.inspect.ADeviceInspectDetail;
import com.thor.palmmall.spi.device.SDeviceInspectDetail;

/**
 * @author wolv
 *
 */
public class ADeviceInspectDetailConverter
    implements Converter<SDeviceInspectDetail, ADeviceInspectDetail> {

  public static ADeviceInspectDetailConverter getInstance() {
    if (instance == null)
      instance = new ADeviceInspectDetailConverter();
    return instance;
  }

  private static ADeviceInspectDetailConverter instance;

  private ADeviceInspectDetailConverter() {
  }

  @Override
  public ADeviceInspectDetail convert(SDeviceInspectDetail source) {
    if (source == null)
      return null;

    ADeviceInspectDetail target = new ADeviceInspectDetail();
    target.setDevice(UCN.newInstance(source.getDevice()));
    if (source.getItems() != null) {
      target.setItems(new ArrayList<KV>());
      for (KV sourceKV : source.getItems())
        target.getItems().add(KV.newInstance(sourceKV));
    }
    target.setLineNo(source.getLineNo());
    target.setNormal(source.isNormal());
    target.setPosition(source.getPosition());
    target.setAttachments(
        ConverterUtil.convert(source.getAttachments(), AAttachmentConverter.getInstance()));

    return target;
  }

}
